/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Administrator
 */
public class daiyuyue extends HttpServlet {

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        int item = Integer.parseInt(request.getParameter("i"));
        int i = 0;
        if(item>15)item=15;
        String data1 = "{\"models\":\"橱下RO机(123)\",\"imgs\":\"\",\"username\":\"xql\",\"yuyuedanID\":\"XSD13877690757501\",\"address\":\"ffffffffffff\",\"tel\":\"15060897316\",\"yyzhuangtai\":\"待预约\",\"zhuYiSx\":\"不安装不安装不安装不安装不安装\",\"xiaoshoudanId\":\"XSD13877690757501\"}";
        String data2 = "{\"models\":\"橱下RO机(test1)\",\"imgs\":\"\",\"username\":\"清一\",\"yuyuedanID\":\"YYD1388807506197\",\"address\":\"365\",\"tel\":\"13986989635\",\"yyzhuangtai\":\"待预约\",\"zhuYiSx\":\"注意短信注意短信注意短信123\",\"xiaoshoudanId\":\"XSD13888074735871\"}";
        String data = "";
        for (i = 0; i < item; i++) {
            if (i == 0) {
                data = data1;
            } else {
                if (i % 2 != 0) {
                    System.out.println(i % 2 );
                    data = data + ',' + data2;
                } else {
                    System.out.println(i % 2 );
                    data=data + ',' + data1;
                }
            }
        }
        data = '[' + data + ']';
        response.setContentType("text/html;charset=gb2312");
        response.setHeader("Access-Control-Allow-Origin", "*");
        try (PrintWriter out = response.getWriter()) {
            out.println(data);
            out.flush();
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
